﻿
/* 
 * Since 2008 - 2012
 */
package com.hh.bss.interfaces.controller;

import static com.hh.bss.util.extjs.JsonHelper.outJson;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;


import com.hh.bss.auth.dao.*;
import com.hh.bss.auth.entity.*;
import com.hh.bss.auth.service.*;
import com.hh.bss.auth.vo.query.*;
import com.hh.bss.base.*;
import com.hh.bss.common.cache.SystemRoleResourceCache;
import com.hh.bss.common.cache.SystemUserCache;
import com.hh.bss.common.page.*;
import com.hh.bss.common.page.impl.*;
import com.hh.bss.project.entity.SearchProjectCv;
import com.hh.bss.talent.entity.Cv;
import com.hh.bss.talent.entity.CvAttachment;
import com.hh.bss.talent.entity.CvSalary;
import com.hh.bss.talent.service.CvAttachmentService;
import com.hh.bss.talent.service.CvService;
import com.hh.bss.util.*;
import com.hh.bss.util.extjs.ExtJsPageHelper;
import com.hh.bss.util.extjs.JsonHelper;
import com.hh.bss.util.extjs.ListRange;

import java.util.*;





@Controller
public class CvController extends BaseSpringController{
	//默认多列排序,example: username desc,createTime asc
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	private CvService cvService;
	
	
	java.lang.Integer id = null;
	
	private CvAttachmentService cvAttachmentService;
	public void setCvAttachmentServiceImpl(CvAttachmentService service) {
		this.cvAttachmentService = service;
	}	
	
	
	/** 通过spring自动注入 */
	public void setCvServiceImpl(CvService service) {
		this.cvService = service;
	}	
	
	
	
	public void setId(java.lang.Integer val) {
		this.id = val;
	}

	public void cvApplyJob(HttpServletRequest request,HttpServletResponse response) throws IOException
	{
		
		Map<String, Object> result = new HashMap<String, Object>();
		
		Cv cv=new Cv();		
		CvSalary cvSalary=new CvSalary();
		try
		{
			bind(request,cv);
			bind(request,cvSalary);
			Integer jobId=StringHelper.parseInteger(request.getParameter("jobId"), 0);
			String cvMobile=request.getParameter("mobile");
			String cvEmail=request.getParameter("email");
			//保存简历
			//保存人选关系
			//发送邮件
			cvService.cvApplyJob(jobId, cv, cvSalary, cvMobile, cvEmail);
			
			CvAttachment cvAttachment=new CvAttachment();
			cvAttachment.setCreator("system");
			cvAttachment.setCreateDt(new Date());
			cvAttachment.setCvId(cv.getId());
			MultipartHttpServletRequest multipartRequest=null;
			MultipartFile multipartFile =null;
		       try{
		    	   multipartRequest = (MultipartHttpServletRequest) request;		    	  
		    	   multipartFile = multipartRequest.getFile("uploadFile");
		    	   
		       }catch(Exception ex){}
		        
		       //multipart/form-data 提交模式，且提交了文件fileRes,则处理上传文件
		       if (multipartRequest!=null&&multipartFile!=null&&!multipartFile.isEmpty()){
		    	   cvAttachmentService.saveFile(multipartRequest, multipartRequest, cvAttachment);			       
		    	   cvAttachmentService.save(cvAttachment);
		       }
			
			result.put("success", true);
			result.put("msg", "申请成功");
		}
		catch (Exception e)
		{
			result.put("failure", true);
			result.put("msg", e.getMessage());
			e.printStackTrace();
		}
		outJson(response,result);
	}


	
	
}
